#include <iostream>

using namespace std;

class Dog
{
public:
	Dog(int _age)
	{
		age=_age;
	}
	//重载cout<<
	ostream &operator<<(ostream &other)  //ostream &other=cout
	{
		other<<this->age;
		return other;
	} 
	//friend ostream &operator<<(ostream &other,Dog &dog);
	//friend void operator<<(ostream &other,Dog &dog);
	//friend ostream operator<<(ostream other,Dog &dog);
private:
	int age;
};

//作为普通函数去重载cout<<
/* ostream &operator<<(ostream &other,Dog &dog)
{                    
	other<<dog.age;
	return other;  //关键点
} */

/* void operator<<(ostream &other,Dog &dog) //局限性，无法连续输出
{                    
	other<<dog.age;
} */

/* ostream operator<<(ostream other,Dog &dog)  //错误的写法，只能使用ostream的引用，引用就是cout的别名 
{                    
	other<<dog.age;
	return other;
}  */

int main()
{
	Dog dog(5);  //ostream cout;
	Dog dog1(6);
	Dog dog2(7);
	dog1.operator<<(cout);
	dog2.operator<<(cout);
	//operator<<(cout,dog);
	//cout<<dog<<dog1<<dog2<<endl;
	
	
}